'use strict'
/**
 * artical
 */

module.exports = (app) => {
	const { STRING, INTEGER, BOOLEAN, DATE } = app.Sequelize

	const Menu = app.model.define(
		'menu',
		{
			id: {
				type: INTEGER,
				primaryKey: true,
				allowNull: true,
			},
			name: STRING,
			pid: INTEGER,
			grade: INTEGER,
			url: STRING,
			orders: INTEGER,
			path: STRING,
			component: STRING,
			icon_cls: STRING,
			remark: INTEGER,
			description: STRING,
			level: INTEGER,
			keep_alive: {
				type: BOOLEAN,
				defaultValue: true,
			},
			require_auth: {
				type: BOOLEAN,
				defaultValue: true,
			},
			enabled: {
				type: BOOLEAN,
				defaultValue: true,
			},
			createdAt: DATE,
			updatedAt: DATE,
			deletedAt: DATE,
		},
		{
			// 去除createAt，updateAt
			timestamps: true,
			// 实例对应的表名
			tableName: 'menu',
		}
	)
	Menu.associate = function () {
		Menu.belongsToMany(app.model.Role, {
			through: app.model.RoleMenu,
			foreignKey: 'mid',
			otherKey: 'rid',
		})
	}

	return Menu
}
